package com.yuantu.judiciary.serviceimpl;

import com.alibaba.fastjson2.JSON;
import com.yuantu.judiciary.model.dto.CaseNumDTO;
import com.yuantu.judiciary.model.form.EncryptParamForm;
import com.yuantu.judiciary.model.form.SysQueryResultsForm;
import com.yuantu.judiciary.model.vo.SysQueryEntResultsVO;
import com.yuantu.judiciary.model.vo.SysQueryPerResultsVO;
import com.yuantu.judiciary.service.ISysOpenService;
import com.yuantu.judiciary.utils.Sm2Util;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 系统对外开放接口实现
 *
 * @author syw
 * @since 2024-01-08
 **/
@Service
@Slf4j
@RequiredArgsConstructor
public class SysOpenServiceImpl implements ISysOpenService {

    private static final String PRIVATE_KEY = "d5e271039acfa121ac0ec1812c321c1e0ae3fcb1031ad98e0851ee2a9e81d952";
    private static final String PUBLIC_KEY = "041ac968252397eaab8c644f20706a23933786998ced1bbff97387663483e07704ee5c8e82cf267e4080f0c4eee295cef4f1faef0139fd7af4fb078498e4024e51";

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String getQueryPersonResults(EncryptParamForm form) {
        SysQueryResultsForm param = Sm2Util.transferDecryptParam(form.getParam(), SysQueryResultsForm.class, PRIVATE_KEY);
        log.info("查询个人解密参数为: {}", JSON.toJSONString(param));

        // 注册用户
        // 查询结果

        SysQueryPerResultsVO res = new SysQueryPerResultsVO(2, 11, 1, 1, 1, "F5kDJrA3vMmFYqMIFEpV5A==");
        return Sm2Util.encrypt(JSON.toJSONString(res), PUBLIC_KEY);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String getQueryEnterpriseResults(EncryptParamForm form) {
        SysQueryResultsForm formData = Sm2Util.transferDecryptParam(form.getParam(), SysQueryResultsForm.class, PRIVATE_KEY);
        log.info("查询企业解密参数为: {}", JSON.toJSONString(formData));

        // 注册用户
        // 查询结果

        SysQueryEntResultsVO res = new SysQueryEntResultsVO(new CaseNumDTO(27, 0, 27), new CaseNumDTO(0, 0, 0),
                new CaseNumDTO(15, 0, 15), new CaseNumDTO(0, 0, 0),
                new CaseNumDTO(1, 0, 1), new CaseNumDTO(0, 0, 0),
                new CaseNumDTO(0, 0, 0), new CaseNumDTO(1, 0, 1), "F5kDJrA3vMmFYqMIFEpV5A==");
        return Sm2Util.encrypt(JSON.toJSONString(res), PUBLIC_KEY);
    }

}
